1624F - Interacdive Problem - CodeForces Solution


binary search constructive algorithms interactive *2000

Please click on ads to support us..

C++ Code:

#include<bits/stdc++.h>
using namespace std;

const long long inf = (long long) 1e18 + 10;
const int inf1 = (int) 1e9 + 10;
#define int long long
#define dbl long double
#define endl '\n'
#define sc second
#define fr first
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()

#define maxn 


void solve() {
    int n;
    cin >> n;

    int l = 1;
    int r = n-1;
    int ans;
    int cur = 0;
    int sum = 0;
    while(l <= r) {
        int mid = (l+r)/2;
        int c = (cur+1)*n - mid - sum;
        sum+= c;

        cout << "+ " << c << endl;
        cout.flush();

        int qr; cin >> qr;

        if(qr == cur+1) {
            cur++;
            ans = mid;
            l = mid+1;
        }
        else {
            r = mid-1;
        }
    }

    cout << "! " << ans+sum << endl;
    cout.flush();

}

int32_t main() {
    ios::sync_with_stdio(false); cin.tie(0);

    // freopen("in.in", "r", stdin);
    //freopen("out.out", "w", stdout);

    int tt = 1;
    // cin >> tt;
    while(tt--) solve();

}


Comments

Submit
0 Comments
More Questions

977F - Consecutive Subsequence
939A - Love Triangle
755A - PolandBall and Hypothesis
760B - Frodo and pillows
1006A - Adjacent Replacements
1195C - Basketball Exercise
1206A - Choose Two Numbers
1438B - Valerii Against Everyone
822A - I'm bored with life
9A - Die Roll
1430B - Barrels
279B - Books
1374B - Multiply by 2 divide by 6
1093B - Letters Rearranging
1213C - Book Reading
1468C - Berpizza
1546B - AquaMoon and Stolen String
1353C - Board Moves
902A - Visiting a Friend
299B - Ksusha the Squirrel
1647D - Madoka and the Best School in Russia
1208A - XORinacci
1539B - Love Song
22B - Bargaining Table
1490B - Balanced Remainders
264A - Escape from Stones
1506A - Strange Table
456A - Laptops
855B - Marvolo Gaunt's Ring
1454A - Special Permutation